package com.shyroke.daydayzhuandao.respository;

import com.shyroke.daydayzhuanapi.entity.SubjectEntity;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
public interface SubjectRepository extends BaseRepository<SubjectEntity,Integer>{
    List<SubjectEntity> findAllByIsShowIsTrueOrderByIdDesc();

    @Modifying
    @Transactional(rollbackFor = Exception.class)
    @Query("update SubjectEntity p set p.readMount = p.readMount+1 where p.id = ?1")
    void updateCount(Integer subjectId);
}
